* combine LNG datasets produced in R
*********************************************************************
* prelims
********************************************************************************
{
clear all
set more off
cap log close

}
********************************************************************************
* LNG - Barcelona
********************************************************************************
{
* Value
use "$data/int/RelIneqWValBuffYears_08_900.dta", clear

drop Properties
rename Gini VLNG
rename WGini WVLNG
rename p01 Vp01
rename p05 Vp05
rename p10 Vp10
rename p25 Vp25
rename p50 Vp50
rename p75 Vp75
rename p90 Vp90
rename p95 Vp95
rename p99 Vp99
rename MeanVal VMean

local varsr WVLNG VLNG Vp01 Vp05 Vp10 Vp25 Vp50 Vp75 Vp90 Vp95 Vp99 VMean Neighbors

* reshape
reshape wide `varsr', i(PlotCode Year) j(Buffer)

* generate plotID
sort PlotCode
egen PlotID = group(PlotCode)

* store
compress
save "$data/temp/vlng_bcn.dta", replace

* Space
use "$data/int/RelIneqWBuffYears_08_900.dta", clear

drop Properties
rename Gini SLNG
rename WGini WSLNG
rename p01 Sp01
rename p05 Sp05
rename p10 Sp10
rename p25 Sp25
rename p50 Sp50
rename p75 Sp75
rename p90 Sp90
rename p95 Sp95
rename p99 Sp99
rename MeanVal SMean

local varsr WSLNG SLNG Sp01 Sp05 Sp10 Sp25 Sp50 Sp75 Sp90 Sp95 Sp99 SMean Neighbors

reshape wide `varsr', i(PlotCode Year) j(Buffer)

* plotID
sort PlotCode

* store
compress
save "$data/temp/slng_bcn.dta", replace

** put together
use "$data/temp/vlng_bcn.dta", clear

* add space estimates
merge 1:1 PlotCode Year using "$data/temp/slng_bcn.dta"
drop _merge

* store
order PlotCode PlotID Year
compress
save "$data/int/lng_bcn.dta", replace

cap erase "$data/temp/slng_bcn.dta"
cap erase "$data/temp/vlng_bcn.dta"

}
********************************************************************************
* closing
********************************************************************************
{

cap log close
clear all

}
